/* 
 * @name login.js
 * @author : Amissah Gideon<kuulmek@yahoo.com>
 * @version 1.0
*/
var SearchObj = {
       /* Server script url   */
       ssUrl : '',
       width : null,
       callback : null,
       
       /* Function init
        * This function is the constructor of the Object.
        * @param void
        * @return void
        * @access public
        * */
       init:function(url, pwidth, func){
            SearchObj.ssUrl = url;
            SearchObj.width = pwidth;
            SearchObj.callback = func;
            
            /*$("#search-btn").change(function(){
            	$("#search").search();
      	    });*/
            
            $("#search_on").change(function(){
                var value = $(this).val();
            	$("#search").setOptions({
                    extraParams:{search_on:value}
          	    });
      	    });
            
            $("#search").autocomplete(""+SearchObj.ssUrl+"", {
            	width: SearchObj.width,
            	selectFirst: false,
				deferRequestBy: 2000, //miliseconds
                extraParams:{search_on:$("#search_on").val()}
      	    });
            
            $("#search").result(function(event, data, formatted) {
        		if (data){
        			$(this).val(data[1]);
                }
                //Call the callback function
                if(typeof SearchObj.callback == 'function'){
                    SearchObj.callback($(this).val());   
                }
        	});
       }
};
